<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="author" content="zhupeng">
<TITLE>钻石管理</TITLE>
<script type="text/javascript" language="javascript"
	src="../script/common.js"></script>
<script type="text/javascript" language="javascript">

	
			//全局变量
			var org = Common.cOrg();	//当前单位	
			var oper = Common.cOperator();
			var qt = {};				//数据表格对象
			var cnt = {};
			var pbillId = getPara("purchaseBillId");
			var pinpai=org.p200  //切工/琢型 切换
			var exportFlag = false;
			//页面加载方法
			function load(){ 
				Eui.showNavigation();
				//searchForm.orgName.value = Common.cOrg().name;
//				if(org.p200){
//					DWR.syncCall("partyService.getOrgName",org.p200,function(name){
//						pinpai=name
//						alert(name)
//					});
//				}
				Common.initDict("colorType","colorType","全部");
				Common.initDict("neatness","neatness","全部");
				Common.initDict("certificateType","certificateType","全部");
				statusList = Common.getSubsetItems("diamondStatus", [Constants.DiamondStatus_1, Constants.DiamondStatus_2]);
				Common.initDict("diamondStatus",statusList,"全部");
				Common.initDict("cut","cut","全部");
				Common.initDict("shape","shape","全部");
				setPages(["listview","amply","detview","fileView","editdiv"]);	
				if(pbillId){
					$("purchaseBillId").value=pbillId;
				}
				
				//导出增加 价格修改 权限 TODO 采购经理(100008) sa(100000)
				if(oper.id == 100008 || oper.id == 100000)
				{
					exportFlag = true;
				}
				
				createTable();
			} 
			 
			//生成表格，创建QueryTable对象(查询)
			function createTable(){
				var columns = [];
				var discolumns;
				columns[0] = {type:"radio"};
				columns[20]= {title:"操作",width:"15%",render:operationFunc,order:false};													
				discolumns = [0,1,2,3,4,5,6,7,8,9,10,11]
//				alert(org.p200)
				if(org.p200){
					//爱她钻石,切工
					if(org.p200==100001){
						discolumns = [0,1,2,3,4,5,7,8,9,10,13]
					}else if(org.p200==100002){
						discolumns = [0,1,2,3,4,6,7,8,9,10,13]		//珂宝龙，琢型
					}	
				}
				
				var buttonsValue = [];
				if(exportFlag)
				{
					buttonsValue = [{value:"导 入",actions:importFile}];
				}
				
				qt = new QueryTable("diamond_manager_jiehuo","searchForm","datalist",columns,{
					displayColumns:discolumns,
					exportable:false,
					buttons:buttonsValue
				});
			}
			
		function onNew(){
			Rpc.loadPage("editdiv","/aita/diamondView.html")
			cardtypeform.orgName.value = Common.cOrg().name;
			Common.initDict(cardtypeform.neatness,"neatness","请选择");
			Common.initDict(cardtypeform.colorType,"colorType","请选择");
			Common.initDict(cardtypeform.certificateType,"certificateType","请选择");
		
			Common.initDict(cardtypeform.cut,"cut","请选择");
			Common.initDict(cardtypeform.shape,"shape","请选择");
			Common.initDict(cardtypeform.certificateType,"certificateType","请选择");
			Common.initDict("heartAndArrow","heartAndArrow","全部");
			cardtypeform.amount.disabled = false;
			switchPage('editdiv');
		
			var setDetOrg = function(sorg) {				
				cardtypeform.org.value = sorg.id;
				cardtypeform.orgname.value = sorg.name;
			}
			
			var orglink = $("operator_sel_org");
			if (orglink)
				orglink.onclick = function(){
					SystemMgnt.selOrg(setDetOrg)
				}
		}
			
		function importFile(){
			var options = {}
			options.headFile = "diamond_jiehuo";
			var url = spellUrl("../common/import_data.html",options);
			openDialogFrame(url,"导入钻石信息",800,1000);	
		}

		function operationFunc(v,r){
			return "<div style='color:gray'><a href=# onclick=onEidt('"+r[0]+"')>查看</a>";
		}
			
		
	function onEidt(id){
		onNew()
		$("saveBut").onclick=onSave1;
		DWR.call("diamondService.loadDiamond",id,function(data){
			var obj = data.diamond;
			
			var norg = data.org;
			
			obj.weight = Format.fenToYuan(obj.weight);
			obj.amount = obj.amount * parseInt(org.description)/100;
			
			if(obj.photo)
		    	$('operPhotoView').innerHTML = "<img id=picsrc src='" + Common.getPhoto(obj.photo) + "' style='border:1px solid #d0d0d0;' height=100>";
			else
		   		$('operPhotoView').innerHTML = "";
		   		
			Common.setValues(cardtypeform, obj);
			
			if(exportFlag)
			{
				cardtypeform.amount.disabled = false;
			}
			
			cardtypeform.orgName.value = norg.name;
		});
	}
			
	//新增修改的保存
	function onSave1(){
		if(!checkForm("cardtypeform"))return;
		if(pbillId){
			cardtypeform.purchaseBill.value=pbillId
		}else(
			pbillId=0
		)
		var cardTypeObj = Common.getValues(cardtypeform);
		
		var orgName = cardtypeform.orgName.value;
		cardTypeObj.weight = Format.yuanToFen(cardTypeObj.weight);
		DWR.call("diamondService.saveDiamond",cardTypeObj,orgName,pbillId,function(result){
			showInformation("保存成功!");	
			if (photoform.photoFile.value) {
				Site.uploadPic( photoform, "CardType", result.id, "类型名称",onBack)
			}else{
				onBack()
			}
			
		},{blockScreen:"true"});
		
	}
	
	//用于订购单的挑选钻石 
	function onSave() {
			var obj = qt.getRadioValue(true);
			if (!obj){
				showWarning("请选择钻石！");return;
			}
			var v = {id : obj[0],
				name : obj[1]
			}
			dialogBackValue(v);
		}
	
	function onBack(){
		switchPage('listview');
		showData();
	}
	
	//选择机构方法
	function searchSelOrg(){
		SystemMgnt.selOrg(function(sorg) {
				searchForm.orgName.value = sorg.name;
				searchForm.org.value = sorg.id;
			});
	}
	
		//选择机构方法
	function searchSelOrg2(){
		SystemMgnt.selOrg(function(sorg) {
				cardtypeform.orgName.value = sorg.name;
			});
	}
	
	function showData(){
 		searchForm.SystemWeight1.value = searchForm.weight1.value != ''?Format.yuanToFen(searchForm.weight1.value):'';
 		searchForm.SystemWeight2.value = searchForm.weight2.value != ''?Format.yuanToFen(searchForm.weight2.value):'';
	  	qt.showTable();
	}
	
		</script>
</head>
<body onload="load()">
<!--页面导航-->
<div class="nav">
<div id="nav">&nbsp;</div>
</div>
<!--查询静态页面部分-->
<div id="listview"><!--查询条件form-->
<div class="searchForm">
<form id="searchForm" name="searchForm"><input type="hidden"
	id="location" name="location">
<table cellSpacing=0 cellPadding=4 width="100%" border=0 class='col3 label2'>
<input type="hidden" id="SystemWeight1" name="SystemWeight1">
<input type="hidden" id="SystemWeight2" name="SystemWeight2">
<input type="hidden" id="org" name="org">
	<tr>
		
		<td>
		<label>库存位置</label>
		<input type="text" name="orgName" maxlength="20" ><a class="orga" href="#" onclick="searchSelOrg();">&nbsp;&nbsp;</a>		</td>
		<td><label>颜色</label>
          <select name="colorType">
          </select></td>
		
		<td><label></label>
		  <label>克拉</label>
          <input type="text" name="weight1"
			onblur="" maxlength=10 > - <input type="text" name="weight2" onblur="" maxlength=10 > 
		</td>
	
	</tr>
	
	
	<tr>
		<td><label>证书编号</label>
          <input type="text" name="certificateNo"
			onBlur="" maxlength=24></td>
		<td><label>净度</label>
          <select name="neatness">
          </select></td>
          
          <td><label></label>
		  <label>价格</label>
          <input type="text" name="price1"
			onBlur="" maxlength=10> - <input type="text" name="price2" onBlur="" maxlength=10>
		</td>
	</tr>
	
	<tr>
		<td>
			 <label>证书类型</label>  <select name="certificateType"></select>   
			</td>
		<td>
		
		<label>切工</label>
        <select name="cut">
        </select></td>
		
       		<td>
			<label>琢型</label>  <select name="shape"></select>
	        
        	<button type="button" onclick="showData()">查 询</button>
		</td>
	</tr>
	<tr>
		<td>
			 <label>钻石状态</label>  <select name="diamondStatus"></select>   
			</td>
		<td>
		<td id="purchaseBillIdTd"><input type="hidden" id="purchaseBillId" name="purchaseBillId">		
		  <label></label></td>
	</tr>
</table>
</form>
</div>
<div id="datalist"></div>
</div>

<div id=editdiv style="display:none;"></div>
</body>
</HTML>